﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using dotNails.CodeGen.Models;

namespace dotNails.CodeGen.Models.dotNailsLinqToSqlGenerator {
	/// <summary>
	/// Summary description for TableClass.
	/// </summary>
	public class TableClass : CodeBlock {
		private Table Table { get; set; }
		private string DataContextClass { get; set; }
		private ConfigData ConfigData { get; set; }

		public TableClass(Table table, string dataContextClass, ConfigData configData) {
			Table = table;
			ConfigData = configData;
			TemplateFileName = Path.Combine(TemplatePath, "Table.cst");
			DataContextClass = dataContextClass;
		}
		
		public override void PopulateTemplate(BaseCodeTemplate template) {
			base.PopulateTemplate(template);

			TableTemplate tableTemplate = template as TableTemplate;

			if (tableTemplate != null) {
				// Populate properties on the base template
				tableTemplate.EntityBaseClass = "LinqEntityBase";
				tableTemplate.Namespace = "";
				tableTemplate.EntityClass = Table.Type.Name;
				tableTemplate.Table = Table;
				tableTemplate.DataContextClass = DataContextClass;
				tableTemplate.ConfigData = ConfigData;
			}
			else {
				throw new Exception("Template is not of type TableTemplate.  Check the Table.cst file to make sure it inherits from TableTemplate");
			}
		}
	}
}